;; Hesperus User Interface


;; one-key switch theme via @ksqsf at emacs-china
;; the fixed original code is at the end of this doc.
(defvar *Hesperus-default-theme* 'spacemacs-dark)
(defvar *Hesperus-dark-theme* 'spacemacs-dark)
(defvar *Hesperus-light-theme* 'spacemacs-light)
(defvar *Hesperus-current-theme* 'HA-default-theme)


;; use switch function to set diff theme face-attribute via @twlz0ne at emacs-china
(defun Hesperus-switch-to-dark-theme ()
  "One-key switch to dark themes."
  (interactive)
  (cond ((or (eq *Hesperus-current-theme* 'HA-light-theme)
             (eq *Hesperus-current-theme* 'HA-default-theme))
         ;; (disable-theme *Hesperus-light-theme*)
         ;; (load-theme *Hesperus-dark-theme*)
         ;; www.gnu.org/software/emacs/manual/html_node/elisp/Faces-for-Font-Lock.html
         ;; www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html
         (set-face-attribute 'default nil :foreground "#afdd22" :background "#161823") ;; Willow-Green, paint-Black
         (set-face-attribute 'font-lock-builtin-face nil :weight 'semi-bold :foreground "#8dd4e8") ;; Azure
         (set-face-attribute 'font-lock-comment-face nil :slant 'italic :foreground "#bbcdc5") ;; crab-shell
         (set-face-attribute 'font-lock-comment-delimiter-face nil :foreground "#80766e") ;; Wild-goose
         (set-face-attribute 'font-lock-constant-face nil :weight 'bold :foreground "#cca4e3") ;; lilac
         (set-face-attribute 'font-lock-doc-face nil :slant 'italic :foreground "#d3b17d") ;; Withered-Yellow
         (set-face-attribute 'font-lock-function-name-face nil :weight 'bold :foreground "#3de1ad") ;; Emerald
         (set-face-attribute 'font-lock-keyword-face nil :weight 'semi-bold :slant 'italic :foreground "#fff143") ;; goose-Yellow
         ;; (set-face-attribute 'font-lock-string-face nil :foreground "#e9f1f6" :background "#35363a") ;; frost,
         (set-face-attribute 'font-lock-string-face nil :foreground "#e9f1f6" :background "#392f41") ;; frost, crow-Black
         (set-face-attribute 'font-lock-type-face nil :foreground "#fff143") ;; goose-Yellow
         (set-face-attribute 'font-lock-variable-name-face nil :weight 'semi-bold :foreground "#f9906f") ;; Intoxicated-face
         (set-face-attribute 'font-lock-warning-face nil :weight 'bold :slant 'italic :underline t :foreground "#f47759") ;; city-wall-brick
         (set-face-background 'cursor "#ffa631") ;; apricot
         (set-face-background 'hl-line "#426666") ;; Dailv-Green
         (set-face-background 'region "#622a1d") ;; Xuanse-Red-Black
         ;; diff-hl custom faces
         (set-face-background 'diff-hl-insert "#7fecad") ;; Ethereal
         (set-face-foreground 'diff-hl-insert "#057748") ;; pine-Green
         (set-face-background 'diff-hl-change "#8dd4e8") ;; Azure
         (set-face-foreground 'diff-hl-change "#065279") ;; Indigo
         (set-face-background 'diff-hl-delete "#f47759") ;; city-wall-brick
         (set-face-foreground 'diff-hl-delete "#60281e") ;; chestnut
         ;; candidates: #7bcfa6 stone-Cyan #ffc773 turmeric #e4c6d0 Pale-Pinkish-Purple
         (setq *Hesperus-current-theme* 'HA-dark-theme))
        ((eq *Hesperus-current-theme* 'HA-dark-theme)
         (disable-theme *Hesperus-dark-theme*)
         (load-theme *Hesperus-dark-theme*)
         (setq *Hesperus-current-theme* 'HA-default-theme))
        (t (error "Current theme is already dark"))))
(bind-key* "<f10>" #'Hesperus-switch-to-dark-theme)

(defun Hesperus-switch-to-light-theme ()
  "One-key switch to light theme."
  (interactive)
  (cond ((or
          (eq *Hesperus-current-theme* 'HA-dark-theme)
          (eq *Hesperus-current-theme* 'HA-default-theme))
         (disable-theme *Hesperus-dark-theme*)
         (load-theme *Hesperus-light-theme*)
         (set-face-attribute 'default nil :foreground "#065279" :background "#d4f2e7") ;; Indigo, water-Green
         (set-face-attribute 'font-lock-builtin-face nil :weight 'semi-bold :foreground "#057748") ;; pine-Green
         (set-face-attribute 'font-lock-comment-face nil :slant 'italic :foreground "#827100" :background "#e3f9fd") ;; brownish-Green, crystal-White
         (set-face-attribute 'font-lock-constant-face nil :weight 'semi-bold :foreground "#801dae") ;; Cyan-lotus
         (set-face-attribute 'font-lock-doc-face nil :slant 'italic :foreground "#9c5333") ;; ocher
         (set-face-attribute 'font-lock-function-name-face nil :weight 'semi-bold :foreground "#4b5cc4") ;; royal-Blue
         (set-face-attribute 'font-lock-keyword-face nil :weight 'semi-bold :slant 'italic :foreground "#424c50") ;; Raven-Cyan
         (set-face-attribute 'font-lock-string-face nil :foreground "#057748" :background "#bbcdc5") ;; pine-Green, crab-shell
         (set-face-attribute 'font-lock-type-face nil :foreground "#4b5cc4") ;; royal-Blue
         (set-face-attribute 'font-lock-variable-name-face nil :weight 'semi-bold :foreground "#ff2d51") ;; fire
         (set-face-attribute 'font-lock-warning-face nil :weight 'bold :slant 'italic :underline t :foreground "#f20c00") ;; pomegranate
         (set-face-background 'cursor "#896c39") ;; olive-Brown(Autumn)
         (set-face-background 'hl-line "#a4e2c6") ;; wormwood
         (set-face-background 'region "#eedeb0") ;; teeth
         (set-face-foreground 'org-code "#9b4400") ;; Brown-Red
         ;; diff-hl custom faces
         (set-face-background 'diff-hl-insert "#057748") ;; pine-Green
         (set-face-foreground 'diff-hl-insert "#3de1ad") ;; Emerald
         (set-face-background 'diff-hl-change "#4b5cc4") ;; royal-Blue
         (set-face-foreground 'diff-hl-change "#b0a4e3") ;; Snow-Cyan(lilac)
         (set-face-background 'diff-hl-delete "#f47759") ;; city-wall-brick
         (set-face-foreground 'diff-hl-delete "#9b4400") ;; Brown-Red
         ;; candidates: #f3d3e7 water-Red #758a99 ink-ash #bce672 pine-flower-color #e0eee8 duck-egg
         (setq *Hesperus-current-theme* 'HA-light-theme))
        (t (error "Current theme is already light"))))
(bind-key* "<f9>" #'Hesperus-switch-to-light-theme)

(custom-set-faces
 '(ediff-current-diff-A ((t (:foreground "#ff2d51")))) ;; fire
 '(ediff-fine-diff-A ((t (:background "#9b4400" :foreground "#e4c6d0")))) ;; Brown-Red, Pale-Pinkish-Purple
 '(highlight-indentation-current-column-face ((t (:background "#50616d")))) ;; ink
 '(org-block-begin-line ((t (:foreground "#549688")))) ;; copper-Green
 '(org-block-end-line ((t (:foreground "#549688"))))
 )

;; execute face-attribute automatically when Emacs start-up
(Hesperus-switch-to-dark-theme)


;; split window right/below
;; via emacs-china.org/t/topic/945/2
(defun Hesperus-split-window-right ()
  "Split window with another buffer."
  (interactive)
  (select-window (split-window-right))
  (switch-to-buffer (other-buffer)))

(defun Hesperus-split-window-below ()
  "Split window with another buffer."
  (interactive)
  (select-window (split-window-below))
  (switch-to-buffer (other-buffer)))

(bind-key* "C-x 3" #'Hesperus-split-window-right)
(bind-key* "C-x 2" #'Hesperus-split-window-below)


;; blog.csdn.net/xh_acmagic/article/details/78939246
(defun Hesperus-better-font ()
  (interactive)
  ;; english font
  (if (display-graphic-p)
      (progn
        (set-face-attribute 'default nil :font (format "%s:pixelsize=%d" "Source Code Pro" 14)) ;; 11 13 17 19 23
        ;; chinese font, same to chinese-fonts-setup, cnfonts
        (dolist (charset '(kana han symbol cjk-misc bopomofo))
          (set-fontset-font (frame-parameter nil 'font)
                            charset
                            (font-spec :family "Source Han Sans CN" :size 16)))) ;; 14 16 20 22 28
    ))

(defun Hesperus-init-font (frame)
  (with-selected-frame frame
    (if (display-graphic-p)
        (Hesperus-better-font))))

(if (and (fboundp 'daemonp) (daemonp))
    (add-hook 'after-make-frame-functions #'Hesperus-init-font)
  (Hesperus-better-font))


(provide 'Hesperus-UI)
